{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "FireQA"

// By ArtemQa146

const
    firela = 0@
    fireman = 31@
    fireman_driver = 28@
    particle_1 = 30@
    particle_2 = 29@
    progress = 27@
    Coords_x = 26@
    Coords_y = 25@
    Coords_z = 24@
    mode_fire = 23@
    time_work = 60000
end

0087: Coords_x = 0@ // (float)
0087: Coords_y = 1@ // (float)
0087: Coords_z = 2@ // (float)
0085: mode_fire = 4@ // (int)

mode_fire = 1

0842: 4@ = player $PLAYER_CHAR town_number


        
        repeat
        wait 0
        04ED: load_animation  "PedEventsMod"
        until 04EE:   animation "PedEventsMod" loaded

        repeat
        wait 0
        04ED: load_animation  "FINALE"
        until 04EE:   animation "FINALE" loaded
        
        5@ = 277
        
        if 4@ == 1
        then 5@ = 277
        end
        if 4@ == 2
        then 5@ = 279
        end
        if 4@ == 3
        then 5@ = 278
        end
    
        model.Load(544)
        model.Load(5@)
        model.Load(366)
        model.Load(407)
        if
            not model.Available(544)
        then
            repeat
            wait 0
            model.Load(544)
            until model.Available(544)
        end
        if
            not model.Available(5@)
        then
            repeat
            wait 0
            model.Load(5@)
            until model.Available(5@)
        end
        if
            not model.Available(366)
        then
            repeat
            wait 0
            model.Load(366)
            until model.Available(366)
        end
        if
            not model.Available(407)
        then
            repeat
            wait 0
            model.Load(407)
            until model.Available(407)
        end
        038B: load_requested_models
        
        if
            mode_fire == 1
        then
            00A5: firela = create_car 544 at Coords_x Coords_y Coords_z
            009A: fireman = create_actor_pedtype 4 model 5@ at 0.0 0.0 0.0
            0129: fireman_driver = create_actor_pedtype 4 model 5@ in_car firela driverseat
            0464: put_actor fireman into_turret_on_car firela at_car_offset -2.0 0.7 8.8 position 0 shooting_angle_limit 0.0 with_weapon 0
            0175: set_car firela Z_angle_to 3@
            01B2: give_actor fireman weapon 42 ammo 100 // Load the weapon model before using this
            066A: particle_1 = attach_particle "extinguisher" to_actor fireman with_offset 0.0 0.0 0.0 rotation 270.0 0.0 200.0 type 1
            066A: particle_2 = attach_particle "fire_car" to_actor fireman with_offset -3.0 -0.6 -0.5 rotation 0.0 0.0 0.0 type 1
            0883: attach_particle particle_1 to_actor fireman mode 24
            064C: make_particle particle_1 visible
            064C: make_particle particle_2 visible
            0812: AS_actor fireman perform_animation "ladder_fire" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1  // versionB
        else
            00A5: firela = create_car 407 at Coords_x Coords_y Coords_z
            01C8: fireman = create_actor_pedtype 4 model 5@ in_car firela passenger_seat 0
            0129: fireman_driver = create_actor_pedtype 4 model 5@ in_car firela driverseat
            0175: set_car firela Z_angle_to 3@
            066B: particle_2 = attach_particle "fire_car" to_car firela with_offset -5.69 0.0 7.271 type 1
            064C: make_particle particle_2 visible
            
            0A97: 1@ = car firela struct
            0D4E: 1@ = read_struct 1@ offset 0x18 size 4
            0AA7: call_function 0x4C5400 num_params 2 pop 2 "misc_a" 1@ 2@
            if
                2@ <> 0
            then
                0A97: 1@ = car firela struct
                000A: 1@ += 0x950  // m_fDoomHorizontalRotation dd ?
                0A8C: write_memory 1@ size 4 value 0.7 virtual_protect 0
                0A97: 1@ = car firela struct
                000A: 1@ += 0x94C // m_fDoomVerticalRotation dd ?
                0A8C: write_memory 1@ size 4 value 90.0 virtual_protect 0
            end


        end

        model.Destroy(544)
        model.Destroy(5@)
        model.Destroy(366)
        model.Destroy(407)
        
        timera = 0
        progress = 0
        6@ = -1.64
        7@ = -1.3
        
        repeat
        wait 0
        if and
            056E:   car firela defined
            056D:   actor fireman defined
            056D:   actor fireman_driver defined
        then

            if or
                0118:   actor fireman_driver dead
                0118:   actor fireman dead
                0119:   car firela wrecked
                00DB:   actor $PLAYER_ACTOR in_car firela
                80DB:   not actor fireman_driver in_car firela
                051A:   actor fireman damaged_by_actor $PLAYER_ACTOR
                051A:   actor fireman_driver damaged_by_actor $PLAYER_ACTOR
            then
                break
            end
            if or
                not $ACTIVE_INTERIOR == 0
                not locate_car_distance_to_coordinates firela pos Coords_x Coords_y Coords_z radius 3.0
            then
                break
            end
            
            if
                mode_fire == 1
            then
            
                0A97: 1@ = car firela struct
                0D4E: 1@ = read_struct 1@ offset 0x18 size 4
                0AA7: call_function 0x4C5400 num_params 2 pop 2 "misc_b" 1@ 2@

                if
                    2@ <> 0
                then
                    2@ += 0x10
                    0D4E: 3@ = read_struct 2@ offset 0x30 size 4
                    0D4E: 4@ = read_struct 2@ offset 0x34 size 4
                    0D4E: 5@ = read_struct 2@ offset 0x38 size 4
                    0AA6: call_method 0x59B120 struct 2@ num_params 3 pop 0 -1.64 0.0 -1.3
                    0E28: write_struct 2@ offset 0x30 size 4 value 3@
                    0E28: write_struct 2@ offset 0x34 size 4 value 4@
                    0E28: write_struct 2@ offset 0x38 size 4 value 5@
                end


                if
                    timera > time_work
                then

                    progress = 1
                    0650: destroy_particle particle_1
                    0650: destroy_particle particle_2
                    6@ = -1.64
                    7@ = -1.3
                    8@ = -1.6
                    9@ = 8.8
                    10@ = 0.7

                    0812: AS_actor fireman perform_animation "Ladder_slide" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB

                    repeat
                    wait 0
                    if and
                        056E:   car firela defined
                        056D:   actor fireman defined
                        056D:   actor fireman_driver defined
                    then
                        if or
                            0118:   actor fireman_driver dead
                            0118:   actor fireman dead
                            0119:   car firela wrecked
                            00DB:   actor $PLAYER_ACTOR in_car firela
                            80DB:   not actor fireman_driver in_car firela
                            051A:   actor fireman damaged_by_actor $PLAYER_ACTOR
                            051A:   actor fireman_driver damaged_by_actor $PLAYER_ACTOR
                        then
                            break
                        end


                        0464: put_actor fireman into_turret_on_car firela at_car_offset 8@ 10@ 9@ position 0 shooting_angle_limit 0.0 with_weapon 0

                        0A97: 1@ = car firela struct
                        0D4E: 1@ = read_struct 1@ offset 0x18 size 4
                        0AA7: call_function 0x4C5400 num_params 2 pop 2 "misc_b" 1@ 2@

                        if
                            2@ <> 0
                        then
                            2@ += 0x10
                            0D4E: 3@ = read_struct 2@ offset 0x30 size 4
                            0D4E: 4@ = read_struct 2@ offset 0x34 size 4
                            0D4E: 5@ = read_struct 2@ offset 0x38 size 4
                            0AA6: call_method 0x59B120 struct 2@ num_params 3 pop 0 6@ 0.0 7@
                            0E28: write_struct 2@ offset 0x30 size 4 value 3@
                            0E28: write_struct 2@ offset 0x34 size 4 value 4@
                            0E28: write_struct 2@ offset 0x38 size 4 value 5@
                        end

                        if and
                            progress == 1
                            9@ > 2.2
                        then
                            9@ -= 0.1
                            8@ += 0.025
                            10@ -= 0.002
                        else
                            9@ = 2.2
                            progress = 2
                            0812: AS_actor fireman perform_animation "FIN_Cop1_Loop" IFP "FINALE" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                        end


                        if
                            progress == 2
                        then
                            if
                                6@ < 0.0
                            then
                                6@ += 0.01
                            else
                                6@ = 0.0
                                if
                                    7@ < 0.0
                                then
                                    7@ += 0.01
                                else
                                    7@ = 0.0

                                    0465: remove_actor fireman from_turret_mode
                                    01C2: remove_references_to_actor fireman // Like turning an actor into a random pedestrian
                                    wait 400
                                    if 056D:   actor fireman defined
                                    then 0430: put_actor fireman into_car firela passenger_seat 0
                                    end
                                    if 056D:   actor fireman_driver defined
                                    then 01C2: remove_references_to_actor fireman_driver // Like turning an actor into a random pedestrian
                                    end
                                    if
                                        056E:   car firela defined
                                    then
                                        00AF: set_car firela driver_behaviour_to 1
                                        00AE: set_car firela traffic_behaviour_to 4
                                        01C3: remove_references_to_car firela
                                    end
                                    firela = -1
                                    fireman = -1
                                    fireman_driver = -1
                                    break
                                end
                            end
                        end
                    else
                        break
                    end
                    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos Coords_x Coords_y Coords_z radius 120.0
                    break
                end
                
            else
            
                0A97: 1@ = car firela struct
                0D4E: 1@ = read_struct 1@ offset 0x18 size 4
                0AA7: call_function 0x4C5400 num_params 2 pop 2 "misc_a" 1@ 2@

                if
                    2@ <> 0
                then
                    2@ += 0x10
                    2@ += 0x30
                    0D4E: 5@ = read_struct 2@ offset 0x0 size 4
                    0D4E: 6@ = read_struct 2@ offset 0x4 size 4
                    0D4E: 7@ = read_struct 2@ offset 0x8 size 4
                    
                    0407: store_coords_to 1@ 2@ 3@ from_car firela with_offset 5@ 6@ 7@

            
                    0209: 10@ = random_int_in_ranges 300000000 400000000 //  id  WaterCannon
                    //10@ = 300001488
                    0E28: write_struct 0xC80740 offset 0x0 size 4 value 10@ // id    
                    
                    10@ = 0xC //X
                    11@ = 0x10 //Y
                    12@ = 0x14 //Z
                    13@ = 0x30C //  ( ?)

                    for 14@ = 1 to 32 step 1 //   
                    
                        5@ -= 0.18
                        7@ += 0.25
                        0407: store_coords_to 1@ 2@ 3@ from_car firela with_offset 5@ 6@ 7@
                        
                        0E28: write_struct 0xC80740 offset 10@ size 4 value 1@ // 
                        0E28: write_struct 0xC80740 offset 11@ size 4 value 2@
                        0E28: write_struct 0xC80740 offset 12@ size 4 value 3@
                        0E28: write_struct 0xC80740 offset 13@ size 1 value 1 // 

                        10@ += 0xC
                        11@ += 0xC
                        12@ += 0xC
                        13@ += 0x1 // 
                        
                        0D4E: 1@ = struct 0xC80740 offset 0x0 size 4
                        0D4E: 2@ = struct 0xC80740 offset 0x4 size 2
                        0D4E: 3@ = struct 0xC80740 offset 0xC size 4
                        0D4E: 4@ = struct 0xC80740 offset 0x10 size 4
                        0D4E: 8@ = struct 0xC80740 offset 0x14 size 4
                        0AD1: show_formatted_text_highpriority "Id:%d Sec:%d~n~V:%f %f %f~n~%d" time 2000 1@ 2@ 3@ 4@ 8@ 14@

                    end
                end

                if
                    timera > time_work
                then

                    progress = 1
                    0650: destroy_particle particle_2

                    01C2: remove_references_to_actor fireman // Like turning an actor into a random pedestrian
                    if 056D:   actor fireman defined
                    then 0430: put_actor fireman into_car firela passenger_seat 0
                    end
                    if 056D:   actor fireman_driver defined
                    then 01C2: remove_references_to_actor fireman_driver // Like turning an actor into a random pedestrian
                    end
                    if
                        056E:   car firela defined
                    then
                        00AF: set_car firela driver_behaviour_to 1
                        00AE: set_car firela traffic_behaviour_to 4
                        01C3: remove_references_to_car firela
                    end
                    firela = -1
                    fireman = -1
                    fireman_driver = -1
                end
            end
            
            
            
        else
            break
        end
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos Coords_x Coords_y Coords_z radius 120.0
        04EF: release_animation "Flame"
        04EF: release_animation "FINALE"
        04EF: release_animation "PedEventsMod"

        if
            mode_fire == 1
        then
            if
                progress == 0
            then
                0650: destroy_particle particle_1
                0650: destroy_particle particle_2
            end
        else
            if
                progress == 0
            then
                0650: destroy_particle particle_2
            end
        end
        
        if
            locate_char_distance_to_coordinates $PLAYER_ACTOR pos Coords_x Coords_y Coords_z radius 120.0
        then
            if
                056D:   actor fireman defined
            then
                0465: remove_actor fireman from_turret_mode
                01C2: remove_references_to_actor fireman // Like turning an actor into a random pedestrian
            end
            if
                056D:   actor fireman_driver defined
            then
                01C2: remove_references_to_actor fireman_driver // Like turning an actor into a random pedestrian
            end
            if
                056E:   car firela defined
            then
                01C3: remove_references_to_car firela
            end
        else
            if
                056D:   actor fireman defined
            then
                009B: destroy_actor fireman
            end
            if
                056D:   actor fireman_driver defined
            then
                009B: destroy_actor fireman_driver
            end
            if
                056E:   car firela defined
            then
                00A6: destroy_car firela
            end
        end
        
        repeat
        wait 0
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos Coords_x Coords_y Coords_z radius 300.0
        
0A93: terminate_this_custom_script

